package eScrum.entities;

import org.apache.wicket.authroles.authorization.strategies.role.Roles;

public class User extends BaseEntity {

	private static final long serialVersionUID = 1596920890278113246L;

	private long id;
	private String firstName;
	private String lastName;
	private String email;
	private String username;
	private String password;

	private UserStatus status;
	private UserRole role;
	private Developer developer;
	private PowerUser poweruser;
	private ClassicUser classicuser;

	public User(String user, String pass) {
		id = 0;
		username = user;
		password = pass;
		status = UserStatus.ACTIVE;
	}

	public User() {
		id = 0;
		username = null;
		password = null;
		status = UserStatus.ACTIVE;
	}

	private Roles roles;

	public Roles getRoles() {
		return roles;
	}

	public void setRoles(Roles roles) {
		this.roles = roles;
	}

	public UserStatus getStatus() {
		return status;
	}

	public void setStatus(UserStatus status) {
		this.status = status;
	}

	public UserRole getRole() {
		return role;
	}

	public void setRole(UserRole role) {
		this.role = role;
	}

	public Developer getDeveloper() {
		return developer;
	}

	public void setDeveloper(Developer developer) {
		this.developer = developer;
	}

	public PowerUser getPoweruser() {
		return poweruser;
	}

	public void setPoweruser(PowerUser poweruser) {
		this.poweruser = poweruser;
	}

	public ClassicUser getClassicuser() {
		return classicuser;
	}

	public void setClassicuser(ClassicUser classicuser) {
		this.classicuser = classicuser;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setRoles(String role) {
		this.roles = new Roles(role);
	}
	public boolean hasAnyRole(Roles roles) {
		return this.roles.hasAnyRole(roles);
	}

	@Override
	public String toString() {
		return "User [id=" + id + ", firstName=" + firstName + ", lastName="
				+ lastName + ", email=" + email + ", username=" + username
				+ ", password=" + password + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((classicuser == null) ? 0 : classicuser.hashCode());
		result = prime * result
				+ ((developer == null) ? 0 : developer.hashCode());
		result = prime * result + ((email == null) ? 0 : email.hashCode());
		result = prime * result
				+ ((firstName == null) ? 0 : firstName.hashCode());
		result = prime * result + (int) (id ^ (id >>> 32));
		result = prime * result
				+ ((lastName == null) ? 0 : lastName.hashCode());
		result = prime * result
				+ ((password == null) ? 0 : password.hashCode());
		result = prime * result
				+ ((poweruser == null) ? 0 : poweruser.hashCode());
		result = prime * result + ((role == null) ? 0 : role.hashCode());
		result = prime * result + ((status == null) ? 0 : status.hashCode());
		result = prime * result
				+ ((username == null) ? 0 : username.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (classicuser == null) {
			if (other.classicuser != null)
				return false;
		} else if (!classicuser.equals(other.classicuser))
			return false;
		if (developer == null) {
			if (other.developer != null)
				return false;
		} else if (!developer.equals(other.developer))
			return false;
		if (email == null) {
			if (other.email != null)
				return false;
		} else if (!email.equals(other.email))
			return false;
		if (firstName == null) {
			if (other.firstName != null)
				return false;
		} else if (!firstName.equals(other.firstName))
			return false;
		if (id != other.id)
			return false;
		if (lastName == null) {
			if (other.lastName != null)
				return false;
		} else if (!lastName.equals(other.lastName))
			return false;
		if (password == null) {
			if (other.password != null)
				return false;
		} else if (!password.equals(other.password))
			return false;
		if (poweruser == null) {
			if (other.poweruser != null)
				return false;
		} else if (!poweruser.equals(other.poweruser))
			return false;
		if (role != other.role)
			return false;
		if (status != other.status)
			return false;
		if (username == null) {
			if (other.username != null)
				return false;
		} else if (!username.equals(other.username))
			return false;
		return true;
	}

}
